package com.future.rabbitmq;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author zou
 * @describe
 * @date 2018/8/29
 */
@Configuration
public class RabbitMqConfig {

    /**
     * 声明队列 管理端消息队列
     *
     * @return
     */
    @Bean
    public Queue queueAdmin() {
        // true表示持久化该队列
        return new Queue(RabbitConstantKeys.QUEUE_ADMIN, true);
    }
    @Bean
    public Queue queueMerchant() {
        return new Queue(RabbitConstantKeys.QUEUE_MERCHANT, true);
    }
    @Bean
    public Queue queueRider() {
        return new Queue(RabbitConstantKeys.QUEUE_RIDER, true);
    }
    @Bean
    public Queue queueMiniprogram() {
        return new Queue(RabbitConstantKeys.QUEUE_MINIPROGRAM, true);
    }

    /**
     * 绑定路由
     *
     * @return
     */
    @Bean
    public Binding bindingAdmin() {
        return BindingBuilder.bind(queueAdmin()).to(directExchange()).with(RabbitConstantKeys.RK_ADMIN);
    }

    @Bean
    public Binding bindingMerchant() {
        return BindingBuilder.bind(queueMerchant()).to(directExchange()).with(RabbitConstantKeys.RK_MERCHANT);
    }

    @Bean
    public Binding bindingMiniprogram() {
        return BindingBuilder.bind(queueMiniprogram()).to(directExchange()).with(RabbitConstantKeys.RK_MINIPROGRAM);
    }

    @Bean
    public Binding bindingRider() {
        return BindingBuilder.bind(queueRider()).to(directExchange()).with(RabbitConstantKeys.RK_RIDER);
    }

    /**
     * 声明交换机
     *
     * @return
     */
    @Bean
    public DirectExchange directExchange() {
        return new DirectExchange(RabbitConstantKeys.EXCHANGE);
    }


}

